#
# Makefile
#
CC = riscv64-unknown-linux-gnu-gcc 
LVGL_DIR_NAME ?= lvgl
LVGL_DIR ?= ${shell pwd}

CFLAGS = -O3 -g0 -I$(LVGL_DIR)/ -march=lib64xthead -mabi=lp64d -mtune=c910 

BIN = demo


CFLAGS = -I$(LVGL_DIR)/ $(DEFINES) $(WARNINGS) $(OPTIMIZATION) -I$(LVGL_DIR)  -I. -I/usr/local/oecore-x86_64/sysroots/riscv64-oe-linux/usr/include/ -I/usr/local/oecore-x86_64/sysroots/riscv64-oe-linux/usr/include/drm/

LDFLAGS = -L/usr/local/oecore-x86_64/sysroots/riscv64-oe-linux/usr/lib/ -L/usr/local/oecore-x86_64/sysroots/riscv64-oe-linux/lib/  -lm  -lpthread  -ldrm  

#Collect the files to compile
MAINSRC = ./main.c

include ./lvgl/lvgl.mk
include ./lv_drivers/lv_drivers.mk
include ./lv_demos/lv_demo.mk

OBJEXT ?= .o

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

MAINOBJ = $(MAINSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)

## MAINOBJ -> OBJFILES

all: default

%.o: %.c
	@$(CC)  $(CFLAGS) -c $< -o $@
	@echo "CC $<"
    
default: $(AOBJS) $(COBJS) $(MAINOBJ)
	$(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)
	cp $(BIN) ~/nfs_rootfs

clean: 
	rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ)

